package com.app.activitys;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

import com.app.bd.BarBD;
import com.app.entidades.Album;
import com.app.entidades.Bandas;
import com.app.entidades.Bar;
import com.app.entidades.Musicas;
import com.app.entidades.Videos;
import com.app.webservice.AlbumRest;
import com.app.webservice.BandasRest;
import com.app.webservice.BarRest;
import com.app.webservice.MusicaRest;
import com.app.webservice.VideoRest;
import com.example.applucianokikao.R;
import com.app.webservice.ListaBandas;

import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.view.View.OnClickListener;

public class MainActivity extends Activity{

	private Dialog dialog;
	private Context contexto;
	private Handler handler;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_inicial);
		dialog = criarDialog();
		contexto = this;
		handler = new Handler();
		dialog.show();

		handler.postDelayed(new Runnable() { 
	         public void run() { 
	        	
	        	 AsyncTask<Void, Void,Void> task = new AsyncTask<Void,Void,Void>(){
	     			@Override
	    			protected Void doInBackground(Void... arg0) {
	    				
	    		
	    				String state = Environment.getExternalStorageState();
	    			    if (Environment.MEDIA_MOUNTED.equals(state)) {
	    			    	System.out.println("Pode");
	    			    	File file = new File(Environment.getExternalStorageDirectory(), "Kikao");
	    				    if (!file.mkdirs()) {
	    				       System.out.println("não foi criado");
	    				    }else{
	    				    	File f = new File(file.getAbsoluteFile()+"/Musicas");
	    				    	if(f.mkdir()){
	    				    		Bitmap bm =  BitmapFactory.decodeResource(getResources(), R.drawable.foto_kikao);
	    				    		
	    				    		File foto = new File(f ,"foto_luciano.jpg"); 
	    				    		FileOutputStream outStream = null;
	    							try {
	    								outStream = new FileOutputStream(foto);
	    								bm.compress(Bitmap.CompressFormat.JPEG ,100,outStream); 
	    						    	
	    								try {
	    									outStream.flush();
	    									outStream.close();
	    								} catch (IOException e) {
	    									// TODO Auto-generated catch block
	    									e.printStackTrace();
	    								}
	    								
	    						    	 
	    							} catch (FileNotFoundException e) {
	    								// TODO Auto-generated catch block
	    								e.printStackTrace();
	    							} 
	    				    	   
	    				    	}
	    				    	
	    				    }
	    			    }
	    				
	    				return null;
	    			}
	    
	    			@Override
	    			protected void onPostExecute(Void result){
	    				Intent intent  = new Intent(MainActivity.this, ActivityMenu.class);
	    				startActivity(intent);
	    			}        		 
	        	 };
	        	 task.execute();
	         } 
	    }, 2000);
			
	}
	
	@Override
	protected void onDestroy() {
		finish();
		super.onDestroy();
	}

	public Dialog criarDialog(){
		Dialog di = new Dialog(this,R.style.Theme_Dialog_Translucent);
        di.setCancelable(false);
        di.setContentView(R.layout.theme);
		return di;
	}
	
	private Bitmap buscaImagem(String nomeImagem){
		Bitmap bmp=null;
			
		    File file = new File(Environment.getExternalStorageDirectory()+"/Kikao/"+nomeImagem);
		    if(file.exists()){
		    	System.out.println("existe");
		    	bmp = BitmapFactory.decodeFile(file.getPath());
		    }else{
		    	System.out.println("não existe");
		    }
			return bmp;
		
	}
	
	private String nomeImagem(String link){
		String[] valores = link.split("/");
		return valores[valores.length-1];
	}

}
